package com.mxpio.erp.plm.controller;

import com.mxpio.erp.common.plm.entity.ProjectDeliverable;
import com.mxpio.erp.common.plm.entity.ProjectInfo;
import com.mxpio.erp.common.plm.entity.ProjectRecoveryOperation;
import com.mxpio.erp.common.plm.entity.ProjectTaskAuditRecords;
import com.mxpio.erp.common.plm.service.ProjectTaskAuditRecordsService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.policy.CrudContext;
import com.mxpioframework.jpa.policy.impl.SmartCrudPolicyAdapter;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.jpa.query.Operator;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.util.List;

@Tag(name = "ProjectTaskAuditRecordsController", description = "项目任务-审核记录")
@RestController
@RequestMapping("/erp/plm/pro/task/audit/records/")
public class ProjectTaskAuditRecordsController {
    @Autowired
    private ProjectTaskAuditRecordsService projectTaskAuditRecordsService;

    @GetMapping("list")
    @Operation(summary = "审核记录列表", description = "审核记录列表（无分页）", method = "GET")
    public Result<List<ProjectTaskAuditRecords>> list(@Parameter(description="查询参数") Criteria criteria) throws UnsupportedEncodingException {
        List<ProjectTaskAuditRecords> list = projectTaskAuditRecordsService.list(ProjectTaskAuditRecords.class, criteria);
        return Result.OK(list);
    }

    @GetMapping("page")
    @Operation(summary = "审核记录列表", description = "审核记录列表（分页）", method = "GET")
    public Result<Page<ProjectTaskAuditRecords>> page(@Parameter(description="查询参数") Criteria criteria, @Parameter(description="每页条数")Integer pageSize, @Parameter(description="页号")Integer pageNo) throws UnsupportedEncodingException {
        Pageable page = PageRequest.of(pageNo-1, pageSize);
        Page<ProjectTaskAuditRecords> pageResult = projectTaskAuditRecordsService.listPage(ProjectTaskAuditRecords.class, page, criteria);
        return Result.OK(pageResult);
    }

    @GetMapping("list/{taskCode}")
    @Operation(summary = "根据任务编码-获取审核记录列表", description = "根据任务编码-获取审核记录列表", method = "GET")
    public Result<List<ProjectTaskAuditRecords>> getList(@PathVariable(name = "taskCode", required = true) String taskCode) {
        Criteria criteria = Criteria.create().addCriterion("taskCode", Operator.EQ, taskCode);
        List<ProjectTaskAuditRecords> list = projectTaskAuditRecordsService.list(ProjectTaskAuditRecords.class, criteria);
        return Result.OK(list);
    }

    @RequestMapping("one/detail")
    @Operation(summary = "展示审批内容详情", description = "展示审批内容详情")
    public Result<?> getDetail(@RequestBody ProjectTaskAuditRecords projectTaskAuditRecords) {
       return projectTaskAuditRecordsService.getDetail(projectTaskAuditRecords);
    }
}
